#include <stdio.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "esp_log.h"

#include "task_one.h"
#include "xlx_platform.h"

#define TASK_ONE_STACK_SIZE (8*256)

static const char* TAG = "task1";
static const char* THIS_H_FILE_NAME = "task one";

TaskHandle_t task_one_handle;
QueueHandle_t task_one_queue;

static void show_task_one_file_info(void)
{
    TUTU_LOGI(TAG, "%s\r\n",THIS_H_FILE_NAME);
}

/*
 * 线程回调
*/
static void task_one_cb(void *parameters){
    TUTU_LOGI(TAG, "task_id=%d\r\n", *((int *)parameters));
    TUTU_LOGI(TAG, "task_one is running...\r\n");
    while(1){       
        TUTU_LOGI(TAG, ".");
        vTaskDelay(3000 / portTICK_PERIOD_MS); 
    }

    vTaskDelete(task_one_handle);
}

const int t_id = 101;
void task_one_init(void){

    int ret = 0;

    TUTU_LOGI(TAG, "-> %s(%s %s) ", __FUNCTION__, __DATE__, __TIME__);
    show_task_one_file_info();

    ret = xTaskCreate(task_one_cb, "task_one", TASK_ONE_STACK_SIZE,
                    (void *)&t_id, 6, &task_one_handle);
                   // NULL, 6, &task_one_handle);
    
    if (ret != pdTRUE) {
        TUTU_LOGE(TAG, "%s(ret=%d)\r\n", "task_num1 create fail!", ret);        

    }
    else {
         TUTU_LOGI(TAG, "%s(ret=%d)\r\n", "task_num1 create OK", ret);
    }
}